package demo1;

import com.sun.org.apache.bcel.internal.generic.ANEWARRAY;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class CardList {

    private static final String[] SUITS = {"♦","♥","♠","♣"};


    public static List<Card> buyCards(){
        List<Card> cards = new ArrayList<>(52);
        for(int i=0;i<SUITS.length;i++){
            for(int j=1;j<=13;j++){
                String suit = SUITS[i];
                int rank = j;
                Card card = new Card(suit,rank);
                cards.add(card);
            }
        }
        return cards;
    }

    private static void swap(List<Card> list, int i, int j) {
        Card tmp = list.get(i);
        list.set(i, list.get(j));
        list.set(j, tmp);
    }
    //喜洗牌
    public static void shuffle(List<Card> list){
        Random random =  new Random();
        for(int i=list.size()-1;i>0;i--){
            int j = random.nextInt(i);
            swap(list,i,j);
        }


    }



    public static void main(String[] args) {
        List<Card> list0 = buyCards();
        System.out.println(list0);
        shuffle(list0);
        System.out.println(list0);


        //取牌，三个人轮流，没人取5张
        List<List<Card>> list = new ArrayList<>();
        list.add(new ArrayList<>());
        list.add(new ArrayList<>());
        list.add(new ArrayList<>());

        for(int i=0;i<5;i++){
            for(int j=0;j<3;j++){
                Card card = list0.remove(0);
                list.get(j).add(card);
            }
        }

        System.out.println(list.get(0));
        System.out.println(list.get(1));
        System.out.println(list.get(2));



    }


}
